package com.zb.sannuo.maintenance.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zb.sannuo.common.domain.MedicalReport;
import com.zb.sannuo.common.domain.Menu;
import com.zb.sannuo.common.domain.search.SystemSettingsSearch;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.maintenance.service.SystemSettingsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/systemSettings")
@Api(tags = "系统设置管理模块", description = "对系统设置进行CRUD操作")
@CrossOrigin
public class SystemSettingsController {

    @Resource
    private SystemSettingsService systemSettingsService;

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ApiOperation(value = "系统设置分页查询",tags = "分页查询系统设置信息")
    public Result queryIdPatient(Integer page,Integer limit,String searchParams)throws Exception{
        ObjectMapper objectMapper = new ObjectMapper();
        SystemSettingsSearch search =null;
        if (searchParams != null && !"".equals(searchParams)){
            search = objectMapper.readValue(searchParams, SystemSettingsSearch.class);
        }
        Page page1 = systemSettingsService.selectList(page, limit, search);
        System.out.println(page1.getTotal());
        return Result.ok(ResultCode.SUCCESS,page1.getTotal(),page1.getRecords());
    }


    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ApiOperation(value = "增加功能",notes = "增加功能")
    public Result addmedicalReport(MedicalReport medicalReport)throws Exception{
        medicalReport.setUpdateTime(new Date());
        int i = systemSettingsService.addSystemSettings(medicalReport);
        return Result.ok(ResultCode.SUCCESS,i);
    }

    @RequestMapping(value = "update",method = RequestMethod.POST)
    @ApiOperation(value = "修改功能",notes = "修改功能")
    public Result updatemedicalReport(MedicalReport medicalReport)throws Exception{
        int i = systemSettingsService.updateSystemSettings(medicalReport);
        return Result.ok(ResultCode.SUCCESS,i);
    }
}
